package com.plasticcode.log.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 * Using the Hibernate extension here as the standard JPA does not support the hilo generator.
 * Would use a \@TableGenerator with JPA which basically allocates a sequence number through the database. 
 */
@GenericGenerator(
        name = "RunGenerator",
        strategy = "hilo", 
        parameters = { @Parameter(name="max_lo", value="1") })

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Run implements Serializable {
    private Long id;
    private String description;
    private double distance;
    private int heartRate;
    private RunType type;
    private Runner runner;
    
    @Id @GeneratedValue(strategy=GenerationType.TABLE, generator="RunGenerator")
    public Long getId() {
        return id;
    }
    
    private void setId(Long id) {
        this.id = id;
    }
    
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }

    
    public double getDistance() {
        return distance;
    }
    
    public void setDistance(double distance) {
        this.distance = distance;
    }

    @Column(name = "HEART_RATE")
    public int getHeartRate() {
        return heartRate;
    }

    public void setHeartRate(int heartRate) {
        this.heartRate = heartRate;
    }

    public RunType getType() {
        return type;
    }

    public void setType(RunType type) {
        this.type = type;
    }

    @ManyToOne
    public Runner getRunner() {
        return runner;
    }

    public void setRunner(Runner runner) {
        this.runner = runner;
    }
}
